package IC.asm.printer;

import IC.asm.Visitor;
import IC.asm.decl.*;
import IC.asm.operands.*;
import IC.asm.operands.MachineReg.Regs;

/**
 * Converts a ASM instruction to a string
 */
public abstract class ASMPrinter implements Visitor<Object,String> {

	public String visit(LabelDecl that, Object d) {
		return that.toString();
	}

	public String visit(ASMDecl that, Object d) {
		return "\t."+that.getName()+
			((that.getValue()!=null) ? (" "+that.getValue()) : "");
	}

	public String visit(CommentEntry that, Object d) {
		return "\t# "+that.getText();
	}
	
	public String visit(Label that, Object d) {
		return that.getName();
	}

	public String visit(VirtualReg that, Object d) {
		if (that.getBinding() != null) {
			return that.getBinding().accept(this, d);
		}
		else {
			return "tmp" + that.getNum();
		}
	}
}
